﻿using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TSNPro.Base;

namespace TSNPro.OperationControl.Command
{
    public class CommandManager : BaseManager
    {
        public CommandManager() 
        {
    
        }

        protected override void InitImpl(JObject obj)
        {
            base.InitImpl(obj);

            JArray arr = obj["Commands"].ToObject<JArray>();
            foreach (var item in arr)
            {
                JObject value= item.ToObject<JObject>();
                string key = value["Name"].ToString();
                BaseItem baseItem = _factory.CreateInstance(value["Type"].ToString());
                baseItem.Name = key;
                baseItem.SetConfig(value);
                baseItem.SetOtherConfig(value["OtherConfig"].ToObject<JObject>());
                _allItems.Add(baseItem);
            }

            Console.WriteLine(ManagerName(),_allItems.Count,"Items");
            Console.WriteLine(Environment.NewLine);
        }
    }
}
